package com.pl.controller;

import com.pl.domain.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shent
 */
@RestController
@RequestMapping("/json")
public class JsonController {
    @GetMapping("/user/{id}")
    public User getUser(@PathVariable Integer id) {
        return new User(id.longValue(), "用户名测试" + id, "123456");
    }

    @GetMapping("/list")
    public List<User> getUserList() {
        List<User> userList = new ArrayList<>();
        User user1 = new User(1L, "用户名测试1", "123456");
        User user2 = new User(2L, "用户名测试2", "123456");
        userList.add(user1);
        userList.add(user2);
        return userList;
    }

    @GetMapping("/map")
    public Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>(3);
        User user = new User(1L, "用户名测试1", "123456");
        map.put("作者信息", user);
        map.put("博客地址", "http://www.baidu.com");
        map.put("CSDN地址", null);
        map.put("粉丝数量", 1001);
        return map;
    }

}
